if ($.fn.datagrid){
	$.fn.datagrid.defaults.pageSize = 20;
}

$.extend($.fn.validatebox.defaults.rules, {   
	noCn: {   
		validator: function(value){
			return /^[^\u4e00-\u9fa5]{0,}$/.test(value);   
		},   
		message: '只能输入英文或字符。'  
	}
}); 

$.extend($.fn.numberbox.defaults.rules, {   
	range: {   
		validator: function(value, param){ 
			return value >= param[0]&&value <= param[1];   
		},   
		message: '范围必须在{0}~{1}之间。'  
	},
	matprice:{
		validator: function(value, param){ 
			var f = parseFloat(value);
			return (parseInt(f*10))%5 == 0;
		},   
		message: '机器售价必须是0.5元的倍数(不会修改模板价格)。'  
	}
}); 
	


/**
 * 扩展$.messager，增加loader，表单提交时自动全屏蒙版，并提供文件上传百分比计数 
 */
(function($){
	function showPb(opts){
		var options=$.extend({},$.fn.window.defaults,{collapsible:false,minimizable:false,maximizable:false,shadow:false,draggable:false,resizable:false,closed:true,style:{left:"",top:"",right:0,zIndex:$.fn.window.defaults.zIndex++,bottom:-document.body.scrollTop-document.documentElement.scrollTop},onBeforeOpen:function(){
			$(this).window("window").show();
			return false;
		},onBeforeClose:function(){
			$(this).window("window").hide();
			return false;
		},onClose : function() {
			$(this).window('destroy');
		}},{title:"",width:250,height:100,showType:"slide",showSpeed:600,msg:"",timeout:4000},opts);
		
		options.style.zIndex=$.fn.window.defaults.zIndex++;
		
		//var pb = $('<div>').css('width', '200px').progressbar();
		
		var _e=$("<div class=\"messager-uploader-body\"></div>").append('<div class=\"uploader-p-msg\" style="padding: 5px 5px 5px 5px;" >'+options.msg+'</div>').append('<div class=\"uploader-p-bar\" style=\"width:230px;\" ></div>').appendTo("body");
		var bar = _e.find('div.uploader-p-bar');
		bar.progressbar();
		_e.window(options);
		_e.window("window").css(options.style);
		_e.window("open");
		
		return _e;
	}
	
	function showPercent(bar,flag){
		$.getJSON('/upload/counter',function(json){
			if(json){
				flag = 1;
				var v = json.currentSize+'/'+json.fileSize+'  '+json.percent;
				bar.progressbar("setValue",json.percent);
				//bar.progressbar("options").text=v;
				setTimeout(function() {
					showPercent(bar,flag);
				}, 500);
			}else{
				if(flag==0){
					setTimeout(function() {
						showPercent(bar,flag);
					}, 500);
				}
			}
		});
	}
	
	$.extend($.messager,{
		
		loader:function(opts){
			
			var methods= {
				close:function(){
					$('body').children("div.messager-loader-msg").remove();
					$('body').children("div.messager-loader").remove();
					if($('div.messager-uploader-body').length){
						$('div.messager-uploader-body').window('close');
					}
				}
			}
			
			
			if(typeof opts == "string"){
				var f = methods[opts];
				return f();
			}
			if(!$('body>div.messager-loader').length){
				$("<div class=\"messager-loader\" style=\"display:block\"></div>").appendTo("body");
				var msg=$("<div class=\"messager-loader-msg\" style=\"display:block;left:50%\"></div>").html(opts.message).appendTo("body");
				msg.css("marginLeft",-msg.outerWidth()/2);
			}
			if(opts.form){
				var type = $(opts.form).attr('enctype');
				if(type=='multipart/form-data'){
					barwin= showPb({msg:'正在上传文件:'});
					var bar = barwin.find('div.uploader-p-bar');
					setTimeout(function() {
						showPercent(bar,0);
					}, 500);
				}
			}
		}
	});
})(jQuery);

(function($) {
	// 备份jquery的ajax方法
	var _ajax = $.ajax;

	// 重写jquery的ajax方法
	$.ajax = function(opt) {
		// 备份opt中error和success方法
		var fn = {
			error : function(XMLHttpRequest, textStatus, errorThrown) {
			},
			success : function(data, textStatus) {
			}
		}
		fn = $.extend(fn, opt || {});

		// 扩展增强处理
		var _opt = $.extend(opt, {
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				switch (XMLHttpRequest.status) {
				case 515:/* 超时 */
					//openLoginDialog();
					window.location.href = "/portal/backstage-manager/index.htm";
					bg_login_refresh_state = false;
					break;
				case 516:/* 超时 */
					//openLoginDialog();
					window.location.href = "/portal/backstage-manager/index.htm";
					bg_login_refresh_state = false;
					break;
				case 511:/* 效验审核错误 */
					var v = eval('(' + XMLHttpRequest.responseText + ')');
					fn.verror(v);
					break;
				default:
					fn.error(XMLHttpRequest, textStatus, errorThrown);
				}
			},
			success : function(data, textStatus) {
				// 成功回调方法增强处理

				fn.success(data, textStatus);
			}
		});
		_ajax(_opt);
	};
})(jQuery);

/*
 * ! jquery.base64.js 0.1 - https://github.com/yckart/jquery.base64.js Makes
 * Base64 en & -decoding simpler as it is.
 * 
 * Based upon: https://gist.github.com/Yaffle/1284012
 * 
 * Copyright (c) 2012 Yannick Albert (http://yckart.com) Licensed under the MIT
 * license (http://www.opensource.org/licenses/mit-license.php). 2013/02/10
 */
(function($) {

	var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", a256 = '', r64 = [ 256 ], r256 = [ 256 ], i = 0;

	var UTF8 = {

		/**
		 * Encode multi-byte Unicode string into utf-8 multiple single-byte
		 * characters (BMP / basic multilingual plane only)
		 * 
		 * Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 -
		 * U+FFFF in 3 chars
		 * 
		 * @param {String}
		 *            strUni Unicode string to be encoded as UTF-8
		 * @returns {String} encoded string
		 */
		encode : function(strUni) {
			// use regular expressions & String.replace callback function for
			// better efficiency
			// than procedural approaches
			var strUtf = strUni.replace(/[\u0080-\u07ff]/g, // U+0080 - U+07FF
			// => 2 bytes
			// 110yyyyy,
			// 10zzzzzz
			function(c) {
				var cc = c.charCodeAt(0);
				return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f);
			}).replace(
					/[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes
					// 1110xxxx, 10yyyyyy, 10zzzzzz
					function(c) {
						var cc = c.charCodeAt(0);
						return String.fromCharCode(0xe0 | cc >> 12,
								0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3f);
					});
			return strUtf;
		},

		/**
		 * Decode utf-8 encoded string back into multi-byte Unicode characters
		 * 
		 * @param {String}
		 *            strUtf UTF-8 string to be decoded back to Unicode
		 * @returns {String} decoded string
		 */
		decode : function(strUtf) {
			// note: decode 3-byte chars first as decoded 2-byte strings could
			// appear to be 3-byte char!
			var strUni = strUtf.replace(
					/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte
					// chars
					function(c) { // (note parentheses for precence)
						var cc = ((c.charCodeAt(0) & 0x0f) << 12)
								| ((c.charCodeAt(1) & 0x3f) << 6)
								| (c.charCodeAt(2) & 0x3f);
						return String.fromCharCode(cc);
					}).replace(
					/[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars
					function(c) { // (note parentheses for precence)
						var cc = (c.charCodeAt(0) & 0x1f) << 6
								| c.charCodeAt(1) & 0x3f;
						return String.fromCharCode(cc);
					});
			return strUni;
		}
	};

	while (i < 256) {
		var c = String.fromCharCode(i);
		a256 += c;
		r256[i] = i;
		r64[i] = b64.indexOf(c);
		++i;
	}

	function code(s, discard, alpha, beta, w1, w2) {
		s = String(s);
		var buffer = 0, i = 0, length = s.length, result = '', bitsInBuffer = 0;

		while (i < length) {
			var c = s.charCodeAt(i);
			c = c < 256 ? alpha[c] : -1;

			buffer = (buffer << w1) + c;
			bitsInBuffer += w1;

			while (bitsInBuffer >= w2) {
				bitsInBuffer -= w2;
				var tmp = buffer >> bitsInBuffer;
				result += beta.charAt(tmp);
				buffer ^= tmp << bitsInBuffer;
			}
			++i;
		}
		if (!discard && bitsInBuffer > 0)
			result += beta.charAt(buffer << (w2 - bitsInBuffer));
		return result;
	}

	var Plugin = $.base64 = function(dir, input, encode) {
		return input ? Plugin[dir](input, encode) : dir ? null : this;
	};

	Plugin.btoa = Plugin.encode = function(plain, utf8encode) {
		plain = Plugin.raw === false || Plugin.utf8encode || utf8encode ? UTF8
				.encode(plain) : plain;
		plain = code(plain, false, r256, b64, 8, 6);
		return plain + '===='.slice((plain.length % 4) || 4);
	};

	Plugin.atob = Plugin.decode = function(coded, utf8decode) {
		coded = String(coded).split('=');
		var i = coded.length;
		do {
			--i;
			coded[i] = code(coded[i], true, r64, a256, 6, 8);
		} while (i > 0);
		coded = coded.join('');
		return Plugin.raw === false || Plugin.utf8decode || utf8decode ? UTF8
				.decode(coded) : coded;
	};
}(jQuery));

/**
 * @author Haojb
 * 
 * @requires jQuery,EasyUI
 * 
 * panel关闭时回收内存，主要用于layout使用iframe嵌入网页时的内存泄漏问题
 */
$.fn.panel.defaults.onBeforeDestroy = function() {
	var frame = $('iframe', this);
	try {
		if (frame.length > 0) {
			for ( var i = 0; i < frame.length; i++) {
				frame[i].contentWindow.document.write('');
				frame[i].contentWindow.close();
			}
			frame.remove();
			if ($.browser.msie) {
				CollectGarbage();
			}
		}
	} catch (e) {
	}
};

/**
 * 使panel和datagrid在加载时提示
 * 
 * @author Haojb
 * 
 * @requires jQuery,EasyUI
 * 
 */
$.fn.panel.defaults.loadingMessage = '加载中....';
$.fn.datagrid.defaults.loadMsg = '加载中....';

/**
 * @author Haojb
 * 
 * @requires jQuery,EasyUI
 * 
 * 通用错误提示
 * 
 * 用于datagrid/treegrid/tree/combogrid/combobox/form加载数据出错时的操作
 */
var easyuiErrorFunction = function(XMLHttpRequest) {
	$.messager.progress('close');
	$.messager.alert('错误', XMLHttpRequest.responseText);
};
$.fn.datagrid.defaults.onLoadError = easyuiErrorFunction;
$.fn.treegrid.defaults.onLoadError = easyuiErrorFunction;
$.fn.tree.defaults.onLoadError = easyuiErrorFunction;
$.fn.combogrid.defaults.onLoadError = easyuiErrorFunction;
$.fn.combobox.defaults.onLoadError = easyuiErrorFunction;
$.fn.form.defaults.onLoadError = easyuiErrorFunction;

/**
 * @author Haojb
 * 
 * @requires jQuery,EasyUI
 * 
 * 为datagrid、treegrid增加表头菜单，用于显示或隐藏列，注意：冻结列不在此菜单中
 */
var createGridHeaderContextMenu = function(e, field) {
	e.preventDefault();
	var grid = $(this);/* grid本身 */
	var headerContextMenu = this.headerContextMenu;/* grid上的列头菜单对象 */
	if (!headerContextMenu) {
		var tmenu = $('<div style="width:100px;"></div>').appendTo('body');
		var fields = grid.datagrid('getColumnFields');
		for ( var i = 0; i < fields.length; i++) {
			var fildOption = grid.datagrid('getColumnOption', fields[i]);
			if (!fildOption.hidden) {
				$('<div iconCls="icon-ok" field="' + fields[i] + '"/>').html(
						fildOption.title).appendTo(tmenu);
			} else {
				$('<div iconCls="icon-empty" field="' + fields[i] + '"/>')
						.html(fildOption.title).appendTo(tmenu);
			}
		}
		headerContextMenu = this.headerContextMenu = tmenu.menu({
			onClick : function(item) {
				var field = $(item.target).attr('field');
				if (item.iconCls == 'icon-ok') {
					grid.datagrid('hideColumn', field);
					$(this).menu('setIcon', {
						target : item.target,
						iconCls : 'icon-empty'
					});
				} else {
					grid.datagrid('showColumn', field);
					$(this).menu('setIcon', {
						target : item.target,
						iconCls : 'icon-ok'
					});
				}
			}
		});
	}
	headerContextMenu.menu('show', {
		left : e.pageX,
		top : e.pageY
	});
};
$.fn.datagrid.defaults.onHeaderContextMenu = createGridHeaderContextMenu;
$.fn.treegrid.defaults.onHeaderContextMenu = createGridHeaderContextMenu;


/**
 * @author 夏悸
 * 
 * @requires jQuery,EasyUI
 * 
 * 扩展tree，使其支持平滑数据格式
 */
$.fn.tree.defaults.loadFilter = function(data, parent) {
	var opt = $(this).data().tree.options;
	var idFiled, textFiled, parentField;
	if (opt.parentField) {
		idFiled = opt.idFiled || 'id';
		textFiled = opt.textFiled || 'text';
		parentField = opt.parentField;
		var i, l, treeData = [], tmpMap = [];
		for (i = 0, l = data.length; i < l; i++) {
			tmpMap[data[i][idFiled]] = data[i];
		}
		for (i = 0, l = data.length; i < l; i++) {
			if (tmpMap[data[i][parentField]]
					&& data[i][idFiled] != data[i][parentField]) {
				if (!tmpMap[data[i][parentField]]['children'])
					tmpMap[data[i][parentField]]['children'] = [];
				data[i]['text'] = data[i][textFiled];
				tmpMap[data[i][parentField]]['children'].push(data[i]);
			} else {
				data[i]['text'] = data[i][textFiled];
				treeData.push(data[i]);
			}
		}
		return treeData;
	}
	return data;
};

/**
 * @author Haojb
 * 
 * @requires jQuery,EasyUI
 * 
 * 扩展treegrid，使其支持平滑数据格式
 */
$.fn.treegrid.defaults.loadFilter = function(data, parentId) {
	var opt = $(this).data().treegrid.options;
	var idFiled, textFiled, parentField;
	if (opt.parentField) {
		idFiled = opt.idFiled || 'id';
		textFiled = opt.textFiled || 'text';
		parentField = opt.parentField;
		var i, l, treeData = [], tmpMap = [];
		for (i = 0, l = data.length; i < l; i++) {
			tmpMap[data[i][idFiled]] = data[i];
		}
		for (i = 0, l = data.length; i < l; i++) {
			if (tmpMap[data[i][parentField]]
					&& data[i][idFiled] != data[i][parentField]) {
				if (!tmpMap[data[i][parentField]]['children'])
					tmpMap[data[i][parentField]]['children'] = [];
				data[i]['text'] = data[i][textFiled];
				tmpMap[data[i][parentField]]['children'].push(data[i]);
			} else {
				data[i]['text'] = data[i][textFiled];
				treeData.push(data[i]);
			}
		}
		return treeData;
	}
	return data;
};

/**
 * @author Haojb
 * 
 * @requires jQuery,EasyUI
 * 
 * 扩展combotree，使其支持平滑数据格式
 */
$.fn.combotree.defaults.loadFilter = $.fn.tree.defaults.loadFilter;

/**
 * @author Haojb
 * 
 * @requires jQuery,EasyUI
 * 
 * 防止panel/window/dialog组件超出浏览器边界
 * @param left
 * @param top
 */
var easyuiPanelOnMove = function(left, top) {
	var l = left;
	var t = top;
	if (l < 1) {
		l = 1;
	}
	if (t < 1) {
		t = 1;
	}
	var width = parseInt($(this).parent().css('width')) + 14;
	var height = parseInt($(this).parent().css('height')) + 14;
	var right = l + width;
	var buttom = t + height;
	var browserWidth = $(window).width();
	var browserHeight = $(window).height();
	if (right > browserWidth) {
		l = browserWidth - width;
	}
	if (buttom > browserHeight) {
		t = browserHeight - height;
	}
	$(this).parent().css({/* 修正面板位置 */
		left : l,
		top : t
	});
};
$.fn.dialog.defaults.onMove = easyuiPanelOnMove;
$.fn.window.defaults.onMove = easyuiPanelOnMove;
$.fn.panel.defaults.onMove = easyuiPanelOnMove;

/**
 * @author Haojb
 * 
 * @requires jQuery,EasyUI,jQuery cookie plugin
 * 
 * 更换EasyUI主题的方法
 * 
 * @param themeName
 *            主题名称
 */
changeTheme = function(themeName) {
	var $easyuiTheme = $('#easyuiTheme');
	var url = $easyuiTheme.attr('href');
	var href = url.substring(0, url.indexOf('themes')) + 'themes/' + themeName
			+ '/easyui.css';
	$easyuiTheme.attr('href', href);

	var $iframe = $('iframe');
	if ($iframe.length > 0) {
		for ( var i = 0; i < $iframe.length; i++) {
			var ifr = $iframe[i];
			$(ifr).contents().find('#easyuiTheme').attr('href', href);
		}
	}

	$.cookie('easyuiThemeName', themeName, {
		expires : 7
	});
};

/**
 * @author Haojb
 * 
 * @requires jQuery
 * 
 * 将form表单元素的值序列化成对象
 * 
 * @returns object
 */
serializeObject = function(form) {
	var o = {};
	$.each(form.serializeArray(), function(index) {
		if (o[this['name']]) {
			o[this['name']] = o[this['name']] + "," + this['value'];
		} else {
			o[this['name']] = this['value'];
		}
	});
	return o;
};

/**
 * @author Haojb
 * 
 * 增加formatString功能
 * 
 * 使用方法：formatString('字符串{0}字符串{1}字符串','第一个变量','第二个变量');
 * 
 * @returns 格式化后的字符串
 */
formatString = function(str) {
	for ( var i = 0; i < arguments.length - 1; i++) {
		str = str.replace("{" + i + "}", arguments[i + 1]);
	}
	return str;
};

/**
 * @author Haojb
 * 
 * 接收一个以逗号分割的字符串，返回List，list里每一项都是一个字符串
 * 
 * @returns list
 */
stringToList = function(value) {
	if (value != undefined && value != '') {
		var values = [];
		var t = value.split(',');
		for ( var i = 0; i < t.length; i++) {
			values.push('' + t[i]);/* 避免他将ID当成数字 */
		}
		return values;
	} else {
		return [];
	}
};

/**
 * @author Haojb
 * 
 * @requires jQuery
 * 
 * 改变jQuery的AJAX默认属性和方法
 */
$.ajaxSetup({
	type : 'POST',
	error : function(XMLHttpRequest, textStatus, errorThrown) {
		$.messager.progress('close');
		$.messager.alert('错误', XMLHttpRequest.responseText);
	}
});

createGUID = function() {
	var guid = "";
	for ( var i = 1; i <= 32; i++) {
		var n = Math.floor(Math.random() * 16.0).toString(16);
		guid += n;
		/*if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
			guid += "-";*/
	}
	return guid;
}

closeDialogWithCurrentTab = function(dialog) {
	$(dialog).dialog('destroy');
	var index = $('#layout_center_tabs').tabs('getTabIndex',
			$('#layout_center_tabs').tabs('getSelected'));
	$('#layout_center_tabs').tabs('close', index);
}

closeCurrentTab = function(destroyAllDialog) {
	var index = $('#layout_center_tabs').tabs('getTabIndex',
			$('#layout_center_tabs').tabs('getSelected'));

	if (destroyAllDialog) {
		var tab = $('#layout_center_tabs').tabs('getTab', index);
		destroyCurrentAllDialog(tab);
	}
	$('#layout_center_tabs').tabs('close', index);
}

refreshCurrentTab = function() {
	var index = $('#layout_center_tabs').tabs('getTabIndex',
			$('#layout_center_tabs').tabs('getSelected'));
	var tab = $('#layout_center_tabs').tabs('getTab', index);
	destroyCurrentAllDialog(tab);
	tab.panel('refresh');
}

destroyCurrentAllDialog = function(tab) {
	$.each($(document).find('.easyui-dialog'), function(i, dia) {
		$(dia).dialog('destroy');
	});
}

getCurrentTab = function() {
	return $('#layout_center_tabs').tabs('getSelected');
}

updateCurrentTab = function(params) {
	var tab = $('#layout_center_tabs').tabs('getSelected');
	$('#layout_center_tabs').tabs('update', {
		tab : tab,
		options : params
	});
}

closeRightOnCloseCurrentTab = function() {
	clear_right_tools_on_close_tab = true;
}

openLoginDialog = function() {
	$('#user_login_loginDialog').dialog('open');
}

setRightTab = function(options) {
	$('body.easyui-layout').layout('panel', 'east').panel(options);
}

closeRightTab = function() {
	$('body.easyui-layout').layout('panel', 'east').panel({
		href : 'layout_right_tools.htm'
	});
}

showQRCode = function(content) {
	window.showModalDialog("/qr/image?_ct=" + content);
}

openShowDialog = function(url, title, width, height, modal) {
	// window.showModalDialog(url);
	$('<div/>').dialog({
		href : url,
		width : width ? width : '800',
		height : height ? height : '600',
		title : title,
		modal : modal ? modal : true,
		maximizable : false,
		collapsible : false,
		minimizable : false,
		resizable : true,
		onClose : function() {
			$(this).dialog('destroy');
		}
	});
};

/** ****扩展easyui start****** */

(function($) {

	/**
	 * 查询数据表单，扩展自datagrid,用于扩展已存在的datagrid表单 特性： grid:基础表单页地址 toolbar : 工具栏
	 * column:扩展栏
	 * 
	 */
	$.fn.querygrid = function(options, opt) {
		var me = $(this);

		if (typeof options == "string") {
			switch (options) {
			case 'doSearch':
				doSearch(me, opt);
				return;
			}
		}
		options = $.extend({}, $.fn.querygrid.defaults, options || {});
		var data = {};
		$.each(options.query, function(i, d) {// 额外query参数
			var k = '_searcher_' + i;
			data[k] = d;
		});
		if (options.toolbar) {
			$(options.toolbar).find('.search-button').click(
					function() {// 通过toolbar查询query参数
						var qb = {};
						$(options.toolbar).find("[name^='_searcher_']").each(
								function(i, d) {
									qb[$(d).attr('name')] = $(d).val();
									qb = $.extend(qb, data);
									me.datagrid('options').queryParams = qp;
									me.datagrid('reload');
								});
					});
		}
		options['params'] = data;
		$.ajax({
			url : options.grid,
			data : options.params,
			cache : false,
			dataType : "text",
			success : function(result) {
				eval("result=" + result);
				if (options.columns) {
					$.each(result.columns, function(i, column) {
						$.each(options.columns[i], function(j, c) {
							column.push(c);
						});
					});
				}
				if (options.toolbar) {
					result['toolbar'] = options.toolbar;
				}
				if (options.queryParams) {
					result['queryParams'] = options.queryParams;
				}
				me.datagrid(result);
			}
		});

		me.data('options', options);
		// $(this).panel(options);
	}

	$.fn.querygrid.defaults = {
		query : {}
	}

	function doSearch(target, opts) {
		var options = target.data('options');
		var qb = {};
		$.each(options.query, function(i, d) {// 额外query参数
			var k = '_searcher_' + i;
			qb[k] = d;
		});
		qb = $.extend(qb, opts);
		/*
		 * if(opts.toolbar){
		 * $(opts.toolbar).find("[name^='_searcher_']").each(function(i,d){
		 * qb[$(d).attr('name')] = $(d).val(); }); }
		 */
		target.datagrid('options').queryParams = qb;
		target.datagrid('reload');
	}

	/**
	 * 增加工具栏
	 */
	function appendToolbar(target, toolbar) {
		if (typeof toolbar == 'string') {
			$(toolbar).addClass("dialog-toolbar").prependTo(target);
			$(toolbar).show();
		} else {
			$(this).find("div.dialog-toolbar").remove();
			var _21e = $(
					"<div class=\"dialog-toolbar\"><table cellspacing=\"0\" cellpadding=\"0\"><tr></tr></table></div>")
					.prependTo(target);
			var tr = _21e.find("tr");
			for ( var i = 0; i < toolbar.length; i++) {
				var btn = toolbar[i];
				if (btn == "-") {
					$("<td><div class=\"dialog-tool-separator\"></div></td>")
							.appendTo(tr);
				} else {
					var td = $("<td></td>").appendTo(tr);
					var tool = $("<a href=\"javascript:void(0)\"></a>")
							.appendTo(td);
					tool[0].onclick = eval(btn.handler || function() {
					});
					tool.linkbutton($.extend({}, btn, {
						plain : true
					}));
				}
			}
		}
	}

	/**
	 * 文件上传 目标对象为上传文件的form 参数： success(json)成功函数 countPercentUrl:计算百分比地址
	 * showPercent：是否显示百分比计算(默认True)
	 */
	$.fn.fileUpload = function(options) {

		options = $.extend({}, $.fn.fileUpload.defaults, options || {});

		var IFRAME_NAME = 'uploadIframe_' + createGUID();
		ifr = $('<iframe name="' + IFRAME_NAME + '" id="' + IFRAME_NAME
				+ '" style="display:none;"></iframe>');
		ifr.appendTo($('body'));
		$(this).attr('target', IFRAME_NAME); // target目标设为ifr

		ifr.load(function() {
			var response = this.contentWindow.document.body.innerHTML;
			var json = $.parseJSON(response);

			options.finish = true;
			if (options.showPercent) {
				options.progressDialog.dialog('close');
			}
			options.success(json);

			ifr.remove();
			ifr = null; // 清除引用
		});

		if (options.showPercent) {
			var dialog = $('<div>');
			var pb = $('<div>').css('width', '200px').progressbar();
			dialog.append('正在上传,请稍等...').append(pb);
			dialog.dialog({
				width : 215,
				height : 50,
				modal : true,
				title : '',
				noheader : true,
				onClose : function() {
					$(this).dialog('destroy');
				}
			});
			options = $.extend(options, {
				progressDialog : dialog,
				progressbar : pb
			});
			options.progressDialog.dialog('open');
			count_fileUpload_percent(options);
		}
		$(this).submit(); // 提交表单
	}

	$.fn.fileUpload.defaults = {
		showPercent : true
	}

	function count_fileUpload_percent(options) {
		if (options.finish) {
			return;
		}
		$.get(options.countPercentUrl, {}, function(data) {
			var pb = options.progressbar;
			var f = parseFloat(data);
			pb.progressbar('setValue', f);
			if (!options.finish) {
				setTimeout(function() {
					count_fileUpload_percent(options);
				}, 500);
			}
		});
	}

	/**
	 * 预览函数
	 */
	$.fn.preview = function(options) {
		var div = $('#preview_absolute_div');
		if (div.length <= 0) {
			div = $('<div>', {
				id : 'preview_absolute_div'
			}).css('position', 'absolute').appendTo($('body'));
		}
		if (!options.html || options.html == '') {
			return;
		}
		$(this).mouseover(function(e) {
			div.html(options.html);
			// alert(div.html());
			// alert('top:'+e.pageY+'||left:'+e.pageX);
			div.css({
				left : (e.pageX + 5) + 'px',
				top : (e.pageY + 5) + 'px'
			});
			// div.offset({top:,left:});
			div.css('zIndex', '9999');
			div.show();
		});
		$(this).mouseout(function() {
			div.hide();
		})
	}

	/** **********扩展menu的disable&enable方法**************** */
	$.extend($.fn.menu.methods, {
		// 显示遮罩
		hiddenItem : function(jq, item) {
			return jq.each(function() {
				$(item).addClass('hidden');
			});
		},
		showItem : function(jq, item) {
			return jq.each(function() {
				$(item).removeClass('hidden');
			});
		},
		disableItem : function(jq, item) { // disable:true，不可用，false,可用
			return jq.each(function() {
				setDisabled($(item), true);
			});
		},
		enableItem : function(jq, item) { // disable:true，不可用，false,可用
			return jq.each(function() {
				setDisabled($(item), false);

			});
		}
	});

	function setDisabled(target, disabled) {
		var state = target.data('menu.item');
		if (!state) {
			target.data('menu.item', {
				options : {}
			});
		}
		state = target.data('menu.item');

		if (disabled) {
			// state.options.disabled = true;
			var href = $(target).attr('href');

			if (href) {
				state.href = href;
				$(target).attr('href', 'javascript: void(0)');
			}
			var onclick = $(target).attr('onclick');
			if (onclick) {
				state.onclick = onclick;
				state.hover = onclick;

				$(target).attr('onclick', null);
				$(target).unbind('hover');
			}
			$(target).removeClass('menu-disabled');
			$(target).addClass('menu-disabled');
		} else {
			// state.options.disabled = false;
			if (state.href) {
				$(target).attr('href', state.href);
			}
			if (state.onclick) {
				target.bind('click', state.onclick);
			}
			$(target).removeClass('menu-disabled');
		}
		target.data('menu.item', state);
	}
	/** *********扩展menu end*********** */

	$.fn.imggroup = function(options) {
		options = $.extend({}, $.fn.imggroup.defaults, options || {});

		var button = $('<a>').linkbutton({
			iconCls : 'icon-add',
			text : options.buttonText
		});
		var filenameshow = $('<div>');
		var allname = $(this).data('allname');
		if (!allname) {
			$(this).data('allname', []);
		}
		allname = $(this).data('allname');

		$(this).append(button).append(filenameshow);
		button.bind('click', function() {
			var id = createGUID();
			var div = $('<div>', {
				id : id
			});
			allname.push(id);
			var file = $('<input>', {
				type : 'file',
				name : options.name
			}).css('display', 'none');
			file.click();
			file.bind('change',
					function() {
						var del = $('<a>').linkbutton({
							iconCls : 'icon-no',
							plain : true
						});
						div.append(file).append(file.val()).append(del).append(
								'<br/>');
						filenameshow.append(div);
						del.bind('click', function() {
							$(this).parent('div').remove();
						});
					});
		});
	}

	$.fn.imggroup.defaults = {
		buttonText : '选择文件'
	}

	$.fn.searcher = function(options) {
		if (typeof options === "string") {
			var opt = $(this).data('options');
			switch (options) {
			case 'doSearch':
				doSearcher(this, opt);
				break;
			}
		} else {
			$(this).data('options', options);
		}

	}

	function doSearcher(target, options) {
		var searchers = $(target).find("[name^='_searcher_']");
		var qp = {};
		$.each(searchers, function(i, d) {
			var v =$(d).val();
			if(v!=null && v!=''){
				qp[$(d).attr('name')] = $(d).val();
			}
		});
		options.doSearch(qp);
	}

})(jQuery);
/** ****扩展easyui end****** */

